from scipy.signal import max_len_seq

def generate_m_sequence(n, taps=None):
    """
    获取m序列, 其中taps为八进制表示的反馈系数
    比如: generate_m_sequence(4,0o23) 返回 [1 1 1 1 0 0 0 1 0 0 1 1 0 1 0]
    """
    if taps is not None:
        binary = [int(bit) for bit in bin(taps)[2:]]
        ones_idx = [i for i, x in enumerate(binary[::-1]) if x == 1]
        return max_len_seq(n, taps=ones_idx)[0]
    else:
        return max_len_seq(n)[0]
    
print(generate_m_sequence(4, 0o23))
